﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Compiler;
using System.ComponentModel;
using Microsoft.SharePoint.WorkflowActions;
using Microsoft.SharePoint;

namespace WFAGetListName
{
    public class GetListNameActivity : Activity
    {
        [ValidationOption(ValidationOption.Optional)]
        [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
        [BrowsableAttribute(true)]
        public string ReturnValue
        {
            get { return (string)GetValue(ReturnValueProperty); }
            set { SetValue(ReturnValueProperty, value); }
        }
        public static DependencyProperty ReturnValueProperty = DependencyProperty.Register("ReturnValue", typeof(string), typeof(GetListNameActivity));

        // Properties
        [ValidationOption(ValidationOption.Optional), Browsable(true), Description("Context"), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public WorkflowContext __Context
        {
            get
            {
                return (WorkflowContext)base.GetValue(__ContextProperty);
            }
            set
            {
                base.SetValue(__ContextProperty, value);
            }
        }
        public static DependencyProperty __ContextProperty = DependencyProperty.Register("__Context", typeof(WorkflowContext), typeof(GetListNameActivity));

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            var spList = __Context.Web.Lists[new Guid(__Context.ListId)];
            var listTitle = spList.Title;
            
            ReturnValue = listTitle;

            return base.Execute(executionContext);
        }
    }

}
